home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / serien / purity / nr.42 / includes3v1 / includes3v1.lha / Libraries / IFFParse.i < prev    next >
Text File  |  1994-12-04  |  10KB  |  322 lines

  1. { IFFParse.i }
  2.  
  3. {$I   "Include:Exec/Types.i"}
  4. {$I   "Include:Exec/Lists.i"}
  5. {$I   "Include:Exec/Ports.i"}
  6. {$I   "Include:Exec/IO.i"}
  7. {$I   "Include:Devices/ClipBoard.i"}
  8. {$I   "Include:Utility/Hooks.i"}
  9.  
  10. VAR IFFParseBase : Address;
  11.  
  12. {
  13.  * Struct associated with an active IFF stream.
  14.  * "iff_Stream" is a value used by the client's read/write/seek functions -
  15.  * it will not be accessed by the library itself and can have any value
  16.  * (could even be a pointer or a BPTR).
  17.  }
  18. Type
  19.        IFFHandle = Record
  20.         iff_Stream,
  21.         iff_Flags,
  22.         iff_Depth   : Integer;      {  Depth of context stack.  }
  23.         {  There are private fields hiding here.  }
  24.        END;
  25.        IFFHandlePtr = ^IFFHandle;
  26.  
  27. {
  28.  * Bit masks for "iff_Flags" field.
  29.  }
  30. CONST
  31.  IFFF_READ     =  0;                      { read mode - default }
  32.  IFFF_WRITE    =  1;                      { write mode }
  33.  IFFF_RWBITS   =  (IFFF_READ + IFFF_WRITE);        { read/write bits }
  34.  IFFF_FSEEK    =  2;                 { forward seek only }
  35.  IFFF_RSEEK    =  4;                 { random seek }
  36.  IFFF_RESERVED =  $FFFF0000;             { Don't touch these bits. }
  37.  
  38. {
  39.  * When the library calls your stream handler, you'll be passed a pointer
  40.  * to this structure as the "message packet".
  41.  }
  42. Type
  43.        IFFStreamCmd = Record
  44.         sc_Command    : Integer;     {  Operation to be performed (IFFCMD_) }
  45.         sc_Buf        : APTR;         {  Pointer to data buffer              }
  46.         sc_NBytes     : Integer;      {  Number of bytes to be affected      }
  47.        END;
  48.        IFFStreamCmdPtr = ^IFFStreamCmd;
  49. {
  50.  * A node associated with a context on the iff_Stack.  Each node
  51.  * represents a chunk, the stack representing the current nesting
  52.  * of chunks in the open IFF file.  Each context node has associated
  53.  * local context items in the (private) LocalItems list.  The ID, type,
  54.  * size and scan values describe the chunk associated with this node.
  55.  }
  56.        ContextNode = Record
  57.         cn_Node         : MinNode;
  58.         cn_ID,
  59.         cn_Type,
  60.         cn_Size,        {  Size of this chunk             }
  61.         cn_Scan  : Integer;        {  # of bytes read/written so far }
  62.         {  There are private fields hiding here.  }
  63.        END;
  64.        ContextNodePtr = ^ContextNode;
  65.  
  66. {
  67.  * Local context items live in the ContextNode's.  Each class is identified
  68.  * by its lci_Ident code and has a (private) purge vector for when the
  69.  * parent context node is popped.
  70.  }
  71.        LocalContextItem = Record
  72.         lci_Node        : MinNode;
  73.         lci_ID,
  74.         lci_Type,
  75.         lci_Ident       : Integer;
  76.         {  There are private fields hiding here.  }
  77.        END;
  78.        LocalContextItemPtr = ^LocalContextItem;
  79.  
  80. {
  81.  * StoredProperty: a local context item containing the data stored
  82.  * from a previously encountered property chunk.
  83.  }
  84.        StoredProperty = Record
  85.         sp_Size  : Integer;
  86.         sp_Data  : Address;
  87.        END;
  88.        StoredPropertyPtr = ^StoredProperty;
  89.  
  90. {
  91.  * Collection Item: the actual node in the collection list at which
  92.  * client will look.  The next pointers cross context boundaries so
  93.  * that the complete list is accessable.
  94.  }
  95.        CollectionItem = Record
  96.         ci_Next                 : ^CollectionItem;
  97.         ci_Size                 : Integer;
  98.         ci_Data                 : Address;
  99.        END;
  100.        CollectionItemPtr = ^CollectionItem;
  101.  
  102. {
  103.  * Structure returned by OpenClipboard().  You may do CMD_POSTs and such
  104.  * using this structure.  However, once you call OpenIFF(), you may not
  105.  * do any more of your own I/O to the clipboard until you call CloseIFF().
  106.  }
  107.        ClipboardHandle = Record
  108.         cbh_Req                 : IOClipReqPtr;
  109.         cbh_CBport,
  110.         cbh_SatisfyPort         : MsgPortPtr;
  111.        END;
  112.        ClipboardHandlePtr = ^ClipboardHandle;
  113.  
  114. {
  115.  * IFF return codes.  Most functions return either zero for success or
  116.  * one of these codes.  The exceptions are the read/write functions which
  117.  * return positive values for number of bytes or records read or written,
  118.  * or a negative error code.  Some of these codes are not errors per sae,
  119.  * but valid conditions such as EOF or EOC (End of Chunk).
  120.  }
  121. CONST
  122.  IFFERR_EOF            =  -1 ;    {  Reached logical END of file }
  123.  IFFERR_EOC            =  -2 ;    {  About to leave context      }
  124.  IFFERR_NOSCOPE        =  -3 ;    {  No valid scope for property }
  125.  IFFERR_NOMEM          =  -4 ;    {  Internal memory alloc failed}
  126.  IFFERR_READ           =  -5 ;    {  Stream read error           }
  127.  IFFERR_WRITE          =  -6 ;    {  Stream write error          }
  128.  IFFERR_SEEK           =  -7 ;    {  Stream seek error           }
  129.  IFFERR_MANGLED        =  -8 ;    {  Data in file is corrupt     }
  130.  IFFERR_SYNTAX         =  -9 ;    {  IFF syntax error            }
  131.  IFFERR_NOTIFF         =  -10;    {  Not an IFF file             }
  132.  IFFERR_NOHOOK         =  -11;    {  No call-back hook provided  }
  133.  IFF_RETURN2CLIENT     =  -12;    {  Client handler normal return}
  134.  
  135. {
  136.  MAKE_ID(a,b,c,d)        \
  137.         ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  138.      }
  139. {
  140.  * Universal IFF identifiers.
  141.  }
  142.  ID_FORM = 1179603533;
  143.  ID_LIST = 1279873876;
  144.  ID_CAT  = 1128354848;
  145.  ID_PROP = 1347571536;
  146.  ID_NULL = 538976288;
  147.  
  148. {
  149.  * Ident codes for universally recognized local context items.
  150.  }
  151.  IFFLCI_PROP         = 1886547824;
  152.  IFFLCI_COLLECTION   = 1668246636;
  153.  IFFLCI_ENTRYHANDLER = 1701734500;
  154.  IFFLCI_EXITHANDLER  = 1702389860;
  155.  
  156.  
  157. {
  158.  * Control modes for ParseIFF() function.
  159.  }
  160.  IFFPARSE_SCAN         =  0;
  161.  IFFPARSE_STEP         =  1;
  162.  IFFPARSE_RAWSTEP      =  2;
  163.  
  164. {
  165.  * Control modes for StoreLocalItem().
  166.  }
  167.  IFFSLI_ROOT           =  1;      {  Store in default context       }
  168.  IFFSLI_TOP            =  2;      {  Store in current context       }
  169.  IFFSLI_PROP           =  3;      {  Store in topmost FORM OR LIST  }
  170.  
  171. {
  172.  * "Flag" for writing functions.  If you pass this value in as a size
  173.  * to PushChunk() when writing a file, the parser will figure out the
  174.  * size of the chunk for you.  (Chunk sizes >= 2**31 are forbidden by the
  175.  * IFF specification, so this works.)
  176.  }
  177.  IFFSIZE_UNKNOWN       =  -1;
  178.  
  179. {
  180.  * Possible call-back command values.  (Using 0 as the value for IFFCMD_INIT
  181.  * was, in retrospect, probably a bad idea.)
  182.  }
  183.  IFFCMD_INIT    = 0;       {  Prepare the stream for a session    }
  184.  IFFCMD_CLEANUP = 1;       {  Terminate stream session            }
  185.  IFFCMD_READ    = 2;       {  Read bytes from stream              }
  186.  IFFCMD_WRITE   = 3;       {  Write bytes to stream               }
  187.  IFFCMD_SEEK    = 4;       {  Seek on stream                      }
  188.  IFFCMD_ENTRY   = 5;       {  You just entered a new context      }
  189.  IFFCMD_EXIT    = 6;       {  You're about to leave a context     }
  190.  IFFCMD_PURGELCI= 7;       {  Purge a LocalContextItem            }
  191.  
  192. {  Backward compatibility.  Don't use these in new code.  }
  193.  IFFSCC_INIT    = IFFCMD_INIT;
  194.  IFFSCC_CLEANUP = IFFCMD_CLEANUP;
  195.  IFFSCC_READ    = IFFCMD_READ;
  196.  IFFSCC_WRITE   = IFFCMD_WRITE;
  197.  IFFSCC_SEEK    = IFFCMD_SEEK;
  198.  
  199.  
  200.  
  201.  
  202. FUNCTION AllocIFF : IFFHandlePtr;
  203.  External;
  204.  
  205. FUNCTION OpenIFF(Iff : IffHandlePtr; rwMode : Integer) : Integer;
  206.  External;
  207.  
  208. FUNCTION ParseIFF(Iff : IFFHandlePtr; control : Integer) : Integer;
  209.  External;
  210.  
  211. PROCEDURE CloseIFF(IFF : IffHandlePtr);
  212.  External;
  213.  
  214. PROCEDURE FreeIFF(iff : IFFHandlePtr);
  215.  External;
  216.  
  217.  
  218. FUNCTION ReadChunkBytes(IFF : IFFHandlePtr; Buf : Address; Size : Integer) : Integer;
  219.  External;
  220.  
  221. FUNCTION WriteChunkBytes(IFF : IFFHandlePtr; Buf : Address; Size : Integer) : Integer;
  222.  External;
  223.  
  224. FUNCTION ReadChunkRecords(IFF : IFFHandlePtr; Buf : Address; BytesPerRecord, nRecords : Integer) : Integer;
  225.  External;
  226.  
  227. FUNCTION WriteChunkRecords(IFF : IFFHandlePtr; Buf : Address; BytesPerRecord, nRecords : Integer) : Integer;
  228.  External;
  229.  
  230. FUNCTION PushChunk(IFF : IFFHandlePtr; Typ,ID,Size : Integer) : Integer;
  231.  External;
  232.  
  233. FUNCTION PopChunk(IFF : IFFhandlePtr) : Integer;
  234.  External;
  235.  
  236. FUNCTION EntryHandler(IFF : IFFHandlePtr; Typ, ID, position : Integer; Handler : HookPtr; Obj : APTR) : Integer;
  237.  External;
  238.  
  239. FUNCTION ExitHandler(IFF : IFFHandlePtr; Typ, ID, position : Integer; Handler : HookPtr; Obj : APTR) : Integer;
  240.  External;
  241.  
  242. FUNCTION PropChunk(IFF : IFFHandlePtr; Typ, ID : Integer) : Integer;
  243.  External;
  244.  
  245. FUNCTION PropChunks(IFF : IFFHandlePtr; PropArray : ListPtr; nProps : Integer) : Integer;
  246.  External;
  247.  
  248. FUNCTION StopChunk(IFF : IFFHandlePtr; Typ, ID : Integer) : Integer;
  249.  External;
  250.  
  251. FUNCTION StopChunks(IFF : IFFHandlePtr; PropArray : ListPtr; nProps : Integer) : Integer;
  252.  External;
  253.  
  254. FUNCTION CollectionChunk(IFF : IFFHandlePtr; Typ, ID : Integer) : Integer;
  255.  External;
  256.  
  257. FUNCTION CollectionChunks(IFF : IFFHandlePtr; PropArray : ListPtr; nProps : Integer) : Integer;
  258.  External;
  259.  
  260. FUNCTION StopOnExit(IFF : IFFHandlePtr; Typ, ID : Integer) : Integer;
  261.  External;
  262.  
  263. FUNCTION FindProp(IFF : IFFHandlePtr; Typ, ID : Integer) : StoredPropertyPtr;
  264.  External;
  265.  
  266. FUNCTION FindCollection(IFF : IFFHandlePtr; Typ, ID : Integer) : CollectionItemPtr;
  267.  External;
  268.  
  269. FUNCTION CurrentChunk(IFF : IFFHandlePtr) : ContextNodePtr;
  270.  External;
  271.  
  272. FUNCTION ParentChunk(cn : ContextNodePtr) : ContextNodePtr;
  273.  External;
  274.  
  275. FUNCTION AllocLocalItem(Typ,ID,ident,dataSize : Integer) : LocalContextItemPtr;
  276.  External;
  277.  
  278. FUNCTION LocalItemData(li : LocalContextItemPtr) : Address;
  279.  External;
  280.  
  281. PROCEDURE SetLocalItemPurge(li : LocalContextItemPtr; purgeHook : HookPtr);
  282.  External;
  283.  
  284. PROCEDURE FreeLocalItem(li : LocalContextItemPtr);
  285.  External;
  286.  
  287. FUNCTION FindLocalItem(IFF : IFFHandlePtr; Typ, ID, ident : Integer) : LocalContextItemPtr;
  288.  External;
  289.  
  290. FUNCTION StoreLocalItem(IFF : IFFHandlePtr; li : LocalContextItemPtr; pos : Integer) : Integer;
  291.  External;
  292.  
  293. PROCEDURE StoreItemInContext(IFF : IFFHandlePtr; li : LocalContextItemPtr; cn : ContextNodePtr);
  294.  External;
  295.  
  296. PROCEDURE InitIFF(IFF : IFFHandlePtr; flags : Integer; streamHook : HookPtr);
  297.  External;
  298.  
  299. PROCEDURE InitIFFasDOS(IFF : IFFHandlePtr);
  300.  External;
  301.  
  302. PROCEDURE InitIFFasClip(IFF : IFFHandlePtr);
  303.  External;
  304.  
  305. FUNCTION OpenClipboard(unitnum : Integer) : ClipboardHandlePtr;
  306.  External;
  307.  
  308. PROCEDURE CloseClipboard(cb : ClipboardHandlePtr);
  309.  External;
  310.  
  311. FUNCTION GoodID(id : Integer) : Integer;
  312.  External;
  313.  
  314. FUNCTION GoodType(Typ : Integer) : Integer;
  315.  External;
  316.  
  317. FUNCTION IDtoStr(id : Integer; VAR buf : String) : String;
  318.  External;
  319.  
  320.  
  321.  
  322.